
package com.phm.phmneuron.neuron;

import com.phm.phmneuron.ParametersContainer;
import com.phm.phmneuron.ProcessOnParameter;
import com.phm.phmneuron.connection.Connection;
import com.phm.phmneuron.connection.ConnectionsContainer;
import com.phm.phmneuron.connection.NeuronConnectionsContainer;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

/**
 *
 * @author PARHAM
 */
public class Neuron implements Cloneable {
    
    protected final static int DEFAULT_DIMENSION = 2;
    
    public final String id;
    public final ParametersContainer parameters;
    public final NeuronConnectionsContainer connections;
    public final float [] central;
    public final int dimension;
    
    protected LinkedList<float []> _signalsBackup = new LinkedList<>();
    
    protected Neuron (String idobj, 
                      ParametersContainer param,
                      NeuronConnectionsContainer cc,
                      float [] c) {
        id = idobj;
        parameters = (ParametersContainer) param.clone();
        connections = (NeuronConnectionsContainer) cc.clone();
        central = (float []) c.clone();
        dimension = c.length;
    }
    public Neuron (int dim) {
        id = UUID.randomUUID().toString().replace("-", "");
        central = new float [dim];
        parameters = new ParametersContainer();
        connections = new NeuronConnectionsContainer (this);
        dimension = dim;
    }
    public Neuron (float [] center) {
        this (center.length);
        setCentroid(center);
    }
    
    public void backupSignal (float [] signal) {
        _signalsBackup.add(signal);
    }
    public List<float []> getBackedupSignal () {
        return _signalsBackup;
    }
    public void clearBackedUpSignal () {
        _signalsBackup.clear();
    }
    
    public final int getDimension () {
        return central.length;
    }
    public final void setCentroid (float [] data) {
        if (data != null && central.length == data.length) {
            System.arraycopy(data, 0, central, 0, central.length);
        }
    }
    
    @Override
    public boolean equals (Object obj) {
        return (obj != null && 
                obj instanceof Neuron &&
                obj.hashCode() == hashCode()) ? true : false;
    }
    @Override
    public int hashCode() {
        return Objects.hashCode(this.id);
    }
    @Override
    public Object clone () {
        return new Neuron(id, parameters, connections, central);
    }
}
